<!doctype html>



  


<html class="theme-next pisces use-motion">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>



<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />












  
  
  <link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />




  
  
  
  

  
    
    
  

  

  

  

  
    
      
    

    
  

  
    
    
    <link href="//fonts.googleapis.com/css?family=Monda:300,300italic,400,400italic,700,700italic|consolas:300,300italic,400,400italic,700,700italic&subset=latin,latin-ext" rel="stylesheet" type="text/css">
  






<link href="/lib/font-awesome/css/font-awesome.min.css?v=4.4.0" rel="stylesheet" type="text/css" />

<link href="/css/main.css?v=5.0.1" rel="stylesheet" type="text/css" />


  <meta name="keywords" content="Android,Project," />





  <link rel="alternate" href="/atom.xml" title="🐕 @Leeifme" type="application/atom+xml" />




  <link rel="shortcut icon" type="image/x-icon" href="/favicon.ico?v=5.0.1" />






<meta name="description" content="前言：之前写了两篇，但是中间又有很长一段时间没更，我非常惭愧的在这里进行深刻的反省🙁 其实，中间这段时间也没有无作为，其实项目做的差不多了，所以现在赶紧来总结一下…..  由于之前的页面框架搭建以及基础封装，让我们在页面的填充上，省了不少功夫，大大的简化了代码量。  首页item布局实现在上一篇应用市场（二）——基础封装中，我们已经通过网络访问加载数据并解析，在首页已经实现了基本的加载data">
<meta name="keywords" content="Android,Project">
<meta property="og:type" content="article">
<meta property="og:title" content="应用市场（三）——页面数据填充">
<meta property="og:url" content="http://www.leeif.me/coding/android/project/ApplicationMarket/应用市场(三)-页面数据填充/index.html">
<meta property="og:site_name" content="🐕 @Leeifme">
<meta property="og:description" content="前言：之前写了两篇，但是中间又有很长一段时间没更，我非常惭愧的在这里进行深刻的反省🙁 其实，中间这段时间也没有无作为，其实项目做的差不多了，所以现在赶紧来总结一下…..  由于之前的页面框架搭建以及基础封装，让我们在页面的填充上，省了不少功夫，大大的简化了代码量。  首页item布局实现在上一篇应用市场（二）——基础封装中，我们已经通过网络访问加载数据并解析，在首页已经实现了基本的加载data">
<meta property="og:image" content="http://oce2u4egr.bkt.clouddn.com/homelayout.png">
<meta property="og:image" content="http://oce2u4egr.bkt.clouddn.com/%E9%A6%96%E9%A1%B5.gif">
<meta property="og:image" content="http://oce2u4egr.bkt.clouddn.com/%E5%BA%94%E7%94%A8.gif">
<meta property="og:image" content="http://oce2u4egr.bkt.clouddn.com/%E4%B8%93%E9%A2%98.gif">
<meta property="og:image" content="http://oce2u4egr.bkt.clouddn.com/%E6%8E%A8%E8%8D%90.gif">
<meta property="og:image" content="http://oce2u4egr.bkt.clouddn.com/%E6%8E%92%E8%A1%8C.gif">
<meta property="og:updated_time" content="2017-07-02T09:56:58.174Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="应用市场（三）——页面数据填充">
<meta name="twitter:description" content="前言：之前写了两篇，但是中间又有很长一段时间没更，我非常惭愧的在这里进行深刻的反省🙁 其实，中间这段时间也没有无作为，其实项目做的差不多了，所以现在赶紧来总结一下…..  由于之前的页面框架搭建以及基础封装，让我们在页面的填充上，省了不少功夫，大大的简化了代码量。  首页item布局实现在上一篇应用市场（二）——基础封装中，我们已经通过网络访问加载数据并解析，在首页已经实现了基本的加载data">
<meta name="twitter:image" content="http://oce2u4egr.bkt.clouddn.com/homelayout.png">



<script type="text/javascript" id="hexo.configuration">
  var NexT = window.NexT || {};
  var CONFIG = {
    scheme: 'Pisces',
    sidebar: {"position":"right","display":"post"},
    fancybox: true,
    motion: true,
    duoshuo: {
      userId: undefined,
      author: 'Author'
    }
  };
</script>




  <link rel="canonical" href="http://www.leeif.me/coding/android/project/ApplicationMarket/应用市场(三)-页面数据填充/"/>

  <title> 应用市场（三）——页面数据填充 | 🐕 @Leeifme </title>
</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="en">

  










  
  
    
  

  <div class="container one-collumn sidebar-position-right page-post-detail ">
    <div class="headband"></div>
    
    <header id="header_post" class="header" itemscope itemtype="http://schema.org/WPHeader" style="background-image: url('/images/4.jpg');">
      <div class="header-inner-post"><a class="site-home" href="/">🐕 @Leeifme</a>

<div class="site-meta custom-logo">
  
  
  
    <div class="site-meta-headline">
      <a>
        <img class="custom-logo-image" src="/images/logo.png" style="width: 80px"
             alt="🐕 @Leeifme"/>
      </a>
    </div>
  

  
  
</div>

<div class="site-nav-toggle">
  <button>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
    <span class="btn-bar"></span>
  </button>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        
        
           <li class="menu-item menu-item-about">
             <a href="/about" rel="section">
               
                 <i class="menu-item-icon fa fa-fw fa-user"></i> <br />
               
               
               about
             </a>
           </li>
        
      
        
        
        
           <li class="menu-item menu-item-movie">
             <a href="/movie" rel="section">
               
                 <i class="menu-item-icon fa fa-fw fa-superscript"></i> <br />
               
               
               movie
             </a>
           </li>
        
      
        
        
        
           <li class="menu-item menu-item-coding">
             <a href="/categories/coding" rel="section">
               
                 <i class="menu-item-icon fa fa-fw fa-cogs"></i> <br />
               
               
               coding
             </a>
           </li>
        
      
        
        
        
           <li class="menu-item menu-item-archives">
             <a href="/archives" rel="section">
               
                 <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
               
               
               archives
             </a>
           </li>
        
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br />
            
            Search
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup">
 <input type="text" id="local-search-input">
 <span class="search-icon fa fa-search"></span>
 <div id="local-search-result"></div>
 <span class="popup-btn-close">close</span>
</div>


    </div>
  
</nav>

 </div>
      <div class="header-post"> 
  <div class="post-header">
      <div class="tags">
      
        <a href="/tags/Android/" rel="tag" title="Android">Android</a>
      
        <a href="/tags/Project/" rel="tag" title="Project">Project</a>
      
      </div>
      <h1>应用市场（三）——页面数据填充</h1>
      <h2 class="subtitle"></h2>
      <div class="post-time">
        <span class="post-meta-item-text">Posted on </span>
        <time itemprop="dateCreated" datetime="2017-03-17T11:30:05+08:00" content="2017-03-17" title="2017-03-17 11:30:05">
          2017-03-17
        </time>
      </div>
  </div>
 </div>
    </header>


    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  
  

  
  
  

  <article class="post post-type-normal " itemscope itemtype="http://schema.org/Article">

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">
            
            
              
                应用市场（三）——页面数据填充
              
            
          </h1>
        

        <div class="post-meta">
          <span class="post-time">
            <span class="post-meta-item-icon">
              <i class="fa fa-calendar-o"></i>
            </span>
            <span class="post-meta-item-text">Posted on</span>
            <time itemprop="dateCreated" datetime="2017-03-17T11:30:05+08:00" content="2017-03-17">
              2017-03-17
            </time>
          </span>

          
            <span class="post-category" >
              &nbsp; | &nbsp;
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">In</span>
              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/coding/" itemprop="url" rel="index">
                    <span itemprop="name">coding</span>
                  </a>
                </span>

                
                
                  , 
                

              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/coding/android/" itemprop="url" rel="index">
                    <span itemprop="name">android</span>
                  </a>
                </span>

                
                
                  , 
                

              
                <span itemprop="about" itemscope itemtype="https://schema.org/Thing">
                  <a href="/categories/coding/android/project/" itemprop="url" rel="index">
                    <span itemprop="name">project</span>
                  </a>
                </span>

                
                

              
            </span>
          

          <!-- 
            
           -->

          

          
          
             <span id="/coding/android/project/ApplicationMarket/应用市场(三)-页面数据填充/" class="leancloud_visitors" data-flag-title="应用市场（三）——页面数据填充">
               &nbsp; | &nbsp;
               <span class="post-meta-item-icon">
                 <i class="fa fa-eye"></i>
               </span>
               <span class="post-meta-item-text">visitors </span>
               <span class="leancloud-visitors-count"></span>
              </span>
          

          
              &nbsp; | &nbsp;
              <span class="page-pv"><i class="fa fa-eye"> </i>
              <span class="busuanzi-value" id="busuanzi_value_page_pv" ></span>
              </span>
          
        </div>
      </header>
    


    <div class="post-body" itemprop="articleBody">

      
      

      
        <link rel="stylesheet" type="text/css" href="/assets/css/DPlayer.min.css"><script src="/assets/js/DPlayer.min.js"> </script><script src="/assets/js/APlayer.min.js"> </script><blockquote>
<h1 id="前言："><a href="#前言：" class="headerlink" title="前言："></a>前言：</h1><p>之前写了两篇，但是中间又有很长一段时间没更，我非常惭愧的在这里进行深刻的反省🙁</p>
<p>其实，中间这段时间也没有无作为，其实项目做的差不多了，所以现在赶紧来总结一下…..</p>
<hr>
<p>由于之前的页面框架搭建以及基础封装，让我们在页面的填充上，省了不少功夫，大大的简化了代码量。</p>
</blockquote>
<h1 id="首页item布局实现"><a href="#首页item布局实现" class="headerlink" title="首页item布局实现"></a>首页item布局实现</h1><p>在上一篇<code>应用市场（二）——基础封装</code>中，我们已经通过网络访问加载数据并解析，在首页已经实现了基本的加载<code>data.name</code>的效果。</p>
<p>但帅的人怎么可能容忍这么丑的UI展示呢，所以我们需要写个<code>layout</code>在<code>HomeHolder</code>中加载，</p>
<p>布局文件<code>list_item_home</code>，由于代码较多，我就贴张图，看下布局效果，感兴趣可以去我的<a href="https://github.com/LeoStones/ApplicationMarket/tree/master/ApplicationMarket" target="_blank" rel="external">github仓库</a>上clone😘</p>
<a id="more"></a>
<p><img src="http://oce2u4egr.bkt.clouddn.com/homelayout.png" alt="list_item_home"></p>
<h2 id="加载布局"><a href="#加载布局" class="headerlink" title="加载布局"></a>加载布局</h2><p>在<code>HomeHolder</code>中加载布局并初始化控件</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> View <span class="title">initView</span><span class="params">()</span> </span>&#123;</div><div class="line">    <span class="comment">// 1. 加载布局</span></div><div class="line">    View view = UIUtils.inflate(R.layout.list_item_home);</div><div class="line">    <span class="comment">// 2. 初始化控件</span></div><div class="line">    tvName = (TextView) view.findViewById(R.id.tv_name);</div><div class="line">    ivIcon = (ImageView) view.findViewById(R.id.iv_icon);</div><div class="line">    tvSize = (TextView) view.findViewById(R.id.tv_size);</div><div class="line">    tvDesc = (TextView) view.findViewById(R.id.tv_desc);</div><div class="line">    rbStar = (RatingBar) view.findViewById(R.id.rb_star);</div><div class="line">    mBitmapUtils = BitmapHelper.getBitmapUtils();</div><div class="line">   <span class="keyword">return</span> view;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>注：获取BitmapUtils对象, 保证多个模块共用一个BitmapUtils对象,不然多个页面都去new一个Bitmap造成内存溢出,所以我们单例出Bitmap。</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">BitmapHelper</span> </span>&#123;</div><div class="line">    <span class="keyword">private</span> <span class="keyword">static</span> BitmapUtils mBitmapUtils = <span class="keyword">null</span>;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> BitmapUtils <span class="title">getBitmapUtils</span><span class="params">()</span> </span>&#123;</div><div class="line">        <span class="keyword">if</span> (mBitmapUtils == <span class="keyword">null</span>) &#123;</div><div class="line">            <span class="keyword">synchronized</span> (BitmapHelper.class)&#123;</div><div class="line">                <span class="keyword">if</span> (mBitmapUtils == <span class="keyword">null</span>)&#123;</div><div class="line">                    mBitmapUtils = <span class="keyword">new</span> BitmapUtils(UIUtils.getContext());</div><div class="line">                &#125;</div><div class="line">            &#125;</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">return</span> mBitmapUtils;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="根据数据来刷新界面"><a href="#根据数据来刷新界面" class="headerlink" title="根据数据来刷新界面"></a>根据数据来刷新界面</h2><p>实现继承<code>BaseHolder</code>中的<code>refershview</code>方法，把加载到的数据填充到初始化的控件中，</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div></pre></td><td class="code"><pre><div class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">refreshView</span><span class="params">(AppInfo data)</span> </span>&#123;</div><div class="line">    tvName.setText(data.name);</div><div class="line">    tvSize.setText(Formatter.formatFileSize(UIUtils.getContext(),</div><div class="line">            data.size));</div><div class="line">    tvDesc.setText(data.des);</div><div class="line">    rbStar.setRating((<span class="keyword">float</span>) data.stars);</div><div class="line">    mBitmapUtils.display(ivIcon, HttpHelper.URL + <span class="string">"image?name="</span></div><div class="line">            + data.iconUrl);</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="效果"><a href="#效果" class="headerlink" title="效果"></a>效果</h2><p><img src="http://oce2u4egr.bkt.clouddn.com/%E9%A6%96%E9%A1%B5.gif"></p>
<h1 id="应用页面实现"><a href="#应用页面实现" class="headerlink" title="应用页面实现"></a>应用页面实现</h1><p>这里可以很充分的体现出我们之前基础框架搭建以及封装的好处，而且由于应用页面与首页几乎一模一样，所以我们在<code>AppHolder</code>基本照抄首页。</p>
<p>然后再<code>AppProtocol</code>中，继承<code>BaseProtocol</code>并重写方法，加载数据：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AppProtocol</span> <span class="keyword">extends</span> <span class="title">BaseProtocol</span>&lt;<span class="title">ArrayList</span>&lt;<span class="title">AppInfo</span>&gt;&gt; </span>&#123;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getKey</span><span class="params">()</span> </span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="string">"app"</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getParams</span><span class="params">()</span> </span>&#123;</div><div class="line">        <span class="keyword">return</span> <span class="string">""</span>;</div><div class="line">    &#125;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> ArrayList&lt;AppInfo&gt; <span class="title">parseData</span><span class="params">(String result)</span> </span>&#123;</div><div class="line">        <span class="keyword">try</span> &#123;</div><div class="line">            JSONArray ja = <span class="keyword">new</span> JSONArray(result);</div><div class="line">            ArrayList&lt;AppInfo&gt; list = <span class="keyword">new</span> ArrayList&lt;&gt;();</div><div class="line">            <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; ja.length(); i++) &#123;</div><div class="line">                JSONObject jo = ja.getJSONObject(i);</div><div class="line">                AppInfo info = <span class="keyword">new</span> AppInfo();</div><div class="line">                info.des = jo.getString(<span class="string">"des"</span>);</div><div class="line">                info.downloadUrl = jo.getString(<span class="string">"downloadUrl"</span>);</div><div class="line">                info.iconUrl = jo.getString(<span class="string">"iconUrl"</span>);</div><div class="line">                info.id = jo.getString(<span class="string">"id"</span>);</div><div class="line">                info.name = jo.getString(<span class="string">"name"</span>);</div><div class="line">                info.packageName = jo.getString(<span class="string">"packageName"</span>);</div><div class="line">                info.size = jo.getLong(<span class="string">"size"</span>);</div><div class="line">                info.stars = (<span class="keyword">float</span>) jo.getDouble(<span class="string">"stars"</span>);</div><div class="line">                list.add(info);</div><div class="line">            &#125;</div><div class="line">            <span class="keyword">return</span>  list;</div><div class="line">        &#125; <span class="keyword">catch</span> (JSONException e) &#123;</div><div class="line">            e.printStackTrace();</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">return</span> <span class="keyword">null</span>;</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<p>之后又回到<code>AppHolder</code>中刷新界面，在控件中填充数据。</p>
<p>最后在应用页面<code>AppFragment</code>中，new一个MyListview，并加载集合，把数据赋给data，并在<code>getHolder</code>方法中,实现AppHolder，最后实现加载更多<code>onLoadMore</code>的方法。代码这里就不贴了，和（二）中差不多，也可以去我的<a href="https://github.com/LeoStones/ApplicationMarket/tree/master/ApplicationMarket" target="_blank" rel="external">github仓库</a>上看。</p>
<h2 id="效果-1"><a href="#效果-1" class="headerlink" title="效果"></a>效果</h2><p><img src="http://oce2u4egr.bkt.clouddn.com/%E5%BA%94%E7%94%A8.gif"></p>
<h1 id="专题页面实现"><a href="#专题页面实现" class="headerlink" title="专题页面实现"></a>专题页面实现</h1><ul>
<li>加载数据及解析和之前的都一样，<code>SubjectProtocol.java</code></li>
<li>加载布局，初始化控件，给控件添加数据，<code>SubjectHolder.java</code></li>
<li>在<code>SubjectFragment</code>实现方法</li>
</ul>
<p><strong>专题页面实现的难点在于自定义控件宽高比</strong></p>
<p>先看下专题页面的布局<code>list_item_subject</code></p>
<figure class="highlight"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div></pre></td><td class="code"><pre><div class="line">&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"</div><div class="line">              xmlns:market="http://schemas.android.com/apk/res-auto"</div><div class="line">              android:layout_width="match_parent"</div><div class="line">              android:layout_height="wrap_content"</div><div class="line">              android:orientation="vertical" &gt;</div><div class="line">    &lt;LinearLayout</div><div class="line">        android:layout_width="match_parent"</div><div class="line">        android:layout_height="wrap_content"</div><div class="line">        android:layout_marginLeft="5dp"</div><div class="line">        android:layout_marginRight="5dp"</div><div class="line">        android:background="@drawable/list_item_bg_selector"</div><div class="line">        android:orientation="vertical" &gt;</div><div class="line">        &lt;com.leostones.applicationmarket.ui.view.RatioLayout</div><div class="line">            android:layout_width="match_parent"</div><div class="line">            android:layout_height="wrap_content"</div><div class="line">            market:ratio="2.43"&gt;</div><div class="line">            &lt;ImageView</div><div class="line">                android:id="@+id/iv_pic"</div><div class="line">                android:layout_width="match_parent"</div><div class="line">                android:layout_height="match_parent"</div><div class="line">                android:scaleType="fitXY"</div><div class="line">                android:src="@drawable/subject_default"/&gt;</div><div class="line">        &lt;/com.leostones.applicationmarket.ui.view.RatioLayout&gt;</div><div class="line">        &lt;TextView</div><div class="line">            android:id="@+id/tv_title"</div><div class="line">            android:layout_width="match_parent"</div><div class="line">            android:layout_height="wrap_content"</div><div class="line">            android:padding="5dp"</div><div class="line">            android:text="标题"</div><div class="line">            android:textColor="#000"</div><div class="line">            android:textSize="18sp" /&gt;</div><div class="line">    &lt;/LinearLayout&gt;</div><div class="line">&lt;/LinearLayout&gt;</div></pre></td></tr></table></figure>
<p>嗯，没错<code>RatioLayout</code>是自定义的一个宽高比控件：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">RatioLayout</span> <span class="keyword">extends</span> <span class="title">FrameLayout</span> </span>&#123;</div><div class="line">    <span class="keyword">private</span> <span class="keyword">float</span> ratio;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RatioLayout</span><span class="params">(Context context, AttributeSet attrs, <span class="keyword">int</span> defStyleAttr)</span> </span>&#123;</div><div class="line">        <span class="keyword">super</span>(context, attrs, defStyleAttr);</div><div class="line">    &#125;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RatioLayout</span><span class="params">(Context context, AttributeSet attrs)</span> </span>&#123;</div><div class="line">        <span class="keyword">super</span>(context, attrs);</div><div class="line">        <span class="comment">//获取属性值</span></div><div class="line">        TypedArray typedArray = context.obtainStyledAttributes(attrs,R.styleable.RatioLayout);</div><div class="line">        <span class="comment">//id = 属性名_具体属性字段</span></div><div class="line">        ratio = typedArray.getFloat(R.styleable.RatioLayout_ratio, -<span class="number">1</span>);</div><div class="line">        <span class="comment">//回收typedArray 提高性能</span></div><div class="line">        typedArray.recycle();</div><div class="line">        System.out.println(<span class="string">"Retio:"</span> + ratio);</div><div class="line">    &#125;</div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="title">RatioLayout</span><span class="params">(Context context)</span> </span>&#123;</div><div class="line">        <span class="keyword">super</span>(context);</div><div class="line">    &#125;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">protected</span> <span class="keyword">void</span> <span class="title">onMeasure</span><span class="params">(<span class="keyword">int</span> widthMeasureSpec, <span class="keyword">int</span> heightMeasureSpec)</span> </span>&#123;</div><div class="line">        <span class="keyword">int</span> widthMode = MeasureSpec.getMode(widthMeasureSpec);</div><div class="line">        <span class="keyword">int</span> heightMode = MeasureSpec.getMode(heightMeasureSpec);</div><div class="line">        <span class="keyword">int</span> widthSize = MeasureSpec.getSize(widthMeasureSpec);</div><div class="line">        <span class="keyword">int</span> heightSize = MeasureSpec.getSize(heightMeasureSpec);</div><div class="line">        <span class="comment">// MeasureSpec.EXACTLY 确定值, 比如把宽高值写死,或者match_parent</span></div><div class="line">        <span class="comment">// MeasureSpec.AT_MOST 至多, 能撑多大就多大, 类似wrap_content</span></div><div class="line">        <span class="comment">// MeasureSpec.UNSPECIFIED 未指定大小</span></div><div class="line">        <span class="keyword">if</span> (widthMode == MeasureSpec.EXACTLY</div><div class="line">                &amp;&amp; heightMode != MeasureSpec.EXACTLY &amp;&amp; ratio != <span class="number">0</span>) &#123;</div><div class="line">            <span class="comment">// 1. 根据布局宽度推算图片宽度</span></div><div class="line">            <span class="keyword">int</span> imageWidth = widthSize - getPaddingLeft() - getPaddingRight();</div><div class="line">            <span class="comment">// 2. 根据图片宽度和宽高比,推算图片高度</span></div><div class="line">            <span class="keyword">int</span> imageHeight = (<span class="keyword">int</span>) (imageWidth / ratio);</div><div class="line">            <span class="comment">// 3. 根据图片高度, 推算布局高度</span></div><div class="line">            heightSize = imageHeight + getPaddingTop() + getPaddingBottom();</div><div class="line">            <span class="comment">// 4. 根据布局高度, 推算heightMeasureSpec</span></div><div class="line">            heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize,</div><div class="line">                    MeasureSpec.EXACTLY);</div><div class="line">        &#125;</div><div class="line">        <span class="keyword">super</span>.onMeasure(widthMeasureSpec, heightMeasureSpec);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="效果-2"><a href="#效果-2" class="headerlink" title="效果"></a>效果</h2><p><img src="http://oce2u4egr.bkt.clouddn.com/%E4%B8%93%E9%A2%98.gif"></p>
<h1 id="推荐页面实现"><a href="#推荐页面实现" class="headerlink" title="推荐页面实现"></a>推荐页面实现</h1><ul>
<li>加载数据及解析和之前的都一样，<code>RecommendProtocol.java</code></li>
<li>加载布局，初始化控件，给控件添加数据，<code>RecommendHolder.java</code></li>
<li>在<code>RecommendFragment</code>实现方法</li>
</ul>
<p>这次，我们看到在<code>ui -&gt; view -&gt; fly -&gt; ...</code></p>
<p>这也不是我写的🙄🙄🙄，</p>
<p>有动画工具类<code>AnimationUtil</code>，有淡入淡出，放大缩小…</p>
<p>有随机布局<code>RandomLayout</code>，字面意思…</p>
<p>还有<code>StellarMap</code>,是一个核心类，调入上面的方法</p>
<p>最后这个<code>ShakeListener</code>，读取手机里面的传感器，拿到手机的X值，Y值，实现摇一摇一类的功能。</p>
<p>感兴趣的可以去看看。</p>
<p>在<code>RecommendFragment</code>中应用：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div></pre></td><td class="code"><pre><div class="line"><span class="comment">//初始化飞入自定义控件</span></div><div class="line"><span class="keyword">final</span> StellarMap stellar = <span class="keyword">new</span> StellarMap(UIUtils.getContext());</div><div class="line"><span class="comment">//设置内部文字距边缘边距为10dip</span></div><div class="line"><span class="keyword">int</span> padding = UIUtils.dip2px(<span class="number">10</span>);</div><div class="line">stellar.setInnerPadding(padding,padding,padding,padding);</div><div class="line"><span class="comment">//设置数据源</span></div><div class="line">stellar.setAdapter(<span class="keyword">new</span> RecommendAdapter());</div><div class="line"><span class="comment">// 设定展示规则,9行6列(具体以随机结果为准)</span></div><div class="line">stellar.setRegularity(<span class="number">6</span>, <span class="number">9</span>);</div><div class="line"><span class="comment">// 设置默认组为第0组</span></div><div class="line">stellar.setGroup(<span class="number">0</span>, <span class="keyword">true</span>);</div><div class="line"><span class="comment">//摇一摇更换推荐数据</span></div><div class="line">ShakeListener shakeListener = <span class="keyword">new</span> ShakeListener(UIUtils.getContext());</div><div class="line">shakeListener.setOnShakeListener(<span class="keyword">new</span> ShakeListener.OnShakeListener() &#123;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onShake</span><span class="params">()</span> </span>&#123;</div><div class="line">        stellar.zoomIn(); <span class="comment">//跳下一页数据</span></div><div class="line">    &#125;</div><div class="line">&#125;);</div><div class="line"><span class="keyword">return</span> stellar;</div></pre></td></tr></table></figure>
<h2 id="效果-3"><a href="#效果-3" class="headerlink" title="效果"></a>效果</h2><p><img src="http://oce2u4egr.bkt.clouddn.com/%E6%8E%A8%E8%8D%90.gif"></p>
<h1 id="排行页面实现"><a href="#排行页面实现" class="headerlink" title="排行页面实现"></a>排行页面实现</h1><ul>
<li>加载数据及解析和之前的都一样，<code>HotProtocol.java</code></li>
<li>加载布局，初始化控件，给控件添加数据，<code>HotHolder.java</code></li>
<li>在<code>HotFragment</code>实现方法</li>
</ul>
<p>这个页面也用到自定义控件<code>ui -&gt; view -&gt; FlowLayout</code>,也不是我写的🙁</p>
<p>它是按照父窗体的宽度，将数据整齐的排列在一行。</p>
<p>在<code>HotFragment</code>中应用：</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><div class="line">1</div><div class="line">2</div><div class="line">3</div><div class="line">4</div><div class="line">5</div><div class="line">6</div><div class="line">7</div><div class="line">8</div><div class="line">9</div><div class="line">10</div><div class="line">11</div><div class="line">12</div><div class="line">13</div><div class="line">14</div><div class="line">15</div><div class="line">16</div><div class="line">17</div><div class="line">18</div><div class="line">19</div><div class="line">20</div><div class="line">21</div><div class="line">22</div><div class="line">23</div><div class="line">24</div><div class="line">25</div><div class="line">26</div><div class="line">27</div><div class="line">28</div><div class="line">29</div><div class="line">30</div><div class="line">31</div><div class="line">32</div><div class="line">33</div><div class="line">34</div><div class="line">35</div><div class="line">36</div><div class="line">37</div><div class="line">38</div><div class="line">39</div><div class="line">40</div><div class="line">41</div><div class="line">42</div><div class="line">43</div><div class="line">44</div><div class="line">45</div><div class="line">46</div><div class="line">47</div><div class="line">48</div><div class="line">49</div><div class="line">50</div><div class="line">51</div></pre></td><td class="code"><pre><div class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HotFragment</span> <span class="keyword">extends</span> <span class="title">BaseFragment</span> </span>&#123;</div><div class="line">    <span class="keyword">private</span> ArrayList&lt;String&gt; data;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> View <span class="title">onCreateSuccessView</span><span class="params">()</span> </span>&#123;</div><div class="line">        <span class="keyword">int</span> padding = UIUtils.dip2px(<span class="number">10</span>);</div><div class="line">        <span class="comment">//支持上下滑动</span></div><div class="line">        ScrollView scrollView = <span class="keyword">new</span> ScrollView(UIUtils.getContext());</div><div class="line">        <span class="comment">//设置文字边距</span></div><div class="line">        scrollView.setPadding(padding,padding,padding,padding);</div><div class="line">        <span class="comment">//初始化自定义控件</span></div><div class="line">        FlowLayout flowLayout =   <span class="keyword">new</span> FlowLayout(UIUtils.getContext());</div><div class="line">        <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; data.size(); i++) &#123;</div><div class="line">            <span class="keyword">final</span> String wards = data.get(i);</div><div class="line">            TextView textView = <span class="keyword">new</span> TextView(UIUtils.getContext());</div><div class="line">            textView.setText(wards);</div><div class="line">            textView.setTextColor(Color.BLACK);</div><div class="line">            textView.setGravity(Gravity.CENTER);</div><div class="line">            textView.setPadding(padding,padding,padding,padding);</div><div class="line">            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP,<span class="number">18</span>);</div><div class="line">            <span class="comment">// 设置随机文字颜色</span></div><div class="line">            Random random = <span class="keyword">new</span> Random();</div><div class="line">            <span class="keyword">int</span> r = <span class="number">30</span> + random.nextInt(<span class="number">210</span>);</div><div class="line">            <span class="keyword">int</span> g = <span class="number">30</span> + random.nextInt(<span class="number">210</span>);</div><div class="line">            <span class="keyword">int</span> b = <span class="number">30</span> + random.nextInt(<span class="number">210</span>);</div><div class="line">            <span class="keyword">int</span> color = <span class="number">0xffcecece</span>;<span class="comment">// 按下后偏白的背景色</span></div><div class="line">            <span class="comment">// 根据默认颜色和按下颜色, 生成圆角矩形的状态选择器</span></div><div class="line">            Drawable selector = DrawableUtils.getStateListDrawable(</div><div class="line">                    Color.rgb(r, g, b), color, UIUtils.dip2px(<span class="number">6</span>));</div><div class="line">            <span class="comment">// 给TextView设置背景</span></div><div class="line">            textView.setBackground(selector);</div><div class="line">            <span class="comment">// 必须设置点击事件, TextView按下后颜色才会变化</span></div><div class="line">            textView.setOnClickListener(<span class="keyword">new</span> View.OnClickListener() &#123;</div><div class="line">                <span class="meta">@Override</span></div><div class="line">                <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">onClick</span><span class="params">(View v)</span> </span>&#123;</div><div class="line">                    Toast.makeText(UIUtils.getContext(), wards,</div><div class="line">                            Toast.LENGTH_SHORT).show();</div><div class="line">                &#125;</div><div class="line">            &#125;);</div><div class="line">            <span class="comment">// 给自定义控件添加view对象</span></div><div class="line">            flowLayout.addView(textView);</div><div class="line">        &#125;</div><div class="line">        scrollView.addView(flowLayout);</div><div class="line">        <span class="keyword">return</span> scrollView;</div><div class="line">    &#125;</div><div class="line">    <span class="meta">@Override</span></div><div class="line">    <span class="function"><span class="keyword">public</span> ResultState <span class="title">onLoad</span><span class="params">()</span> </span>&#123;</div><div class="line">        HotProtocol protocol = <span class="keyword">new</span> HotProtocol();</div><div class="line">        data = protocol.getData(<span class="number">0</span>);</div><div class="line">        <span class="keyword">return</span> check(data);</div><div class="line">    &#125;</div><div class="line">&#125;</div></pre></td></tr></table></figure>
<h2 id="效果-4"><a href="#效果-4" class="headerlink" title="效果"></a>效果</h2><p><img src="http://oce2u4egr.bkt.clouddn.com/%E6%8E%92%E8%A1%8C.gif"></p>
<h1 id="最后"><a href="#最后" class="headerlink" title="最后"></a>最后</h1><p>其实，看到这，我们也发现了其实由于之前的基础框架的搭建，我们在这里的页面填充，其实都是继承调用重写各种方法，逻辑条理也是很清楚。</p>
<p>虽然由于页面比较多，新建的类比较多，但是很多都是大同小异，所以基本可以Ctrl C+V,在做修改，前面难，但到后面越来越简单。</p>
<p>其实，自己在做这个项目时候，基础并没有很扎实，但是在后面的理解起来，也没有想象中复杂。</p>
<p>源码地址: <a href="https://github.com/LeoStones/ApplicationMarket/tree/master/ApplicationMarket" target="_blank" rel="external">ApplicationMarket</a></p>
<p>感谢关注，欢迎Star💚</p>

      
    </div>


    <div>
      
        

      
    </div>

    <div>
      
        

      
    </div>

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/tags/Android/" rel="tag">#Android</a>
          
            <a href="/tags/Project/" rel="tag">#Project</a>
          
        </div>
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/coding/android/project/ApplicationMarket/应用市场(二)-基础封装/" rel="next" title="应用市场（二）——基础封装">
                <i class="fa fa-chevron-left"></i> 应用市场（二）——基础封装
              </a>
            
          </div>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/technology/other/Git常用命令记录/" rel="prev" title="Git常用命令记录">
                Git常用命令记录 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </article>



    <div class="post-spread">
      
    </div>
  </div>

          
          </div>
          


          
  <div class="comments" id="comments">
    
      <div id="hypercomments_widget"></div>
    
  </div>


        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    <div class="sidebar-inner">

      
      
        
          <ul class="sidebar-nav motion-element">
            <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap" >
              Table of Contents
            </li>
            <li class="sidebar-nav-overview" data-target="site-overview">
              Overview
            </li>
          </ul>
        
      



      <section class="site-overview sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
          <img class="site-author-image" itemprop="image"
               src="/images/avatar.jpg"
               alt="睡沙发的沙皮狗" />
          <p class="site-author-name" itemprop="name">睡沙发的沙皮狗</p>
           
              <p class="site-description motion-element" itemprop="description">睡沙发的沙皮狗 Leeifme</p>
          
        </div>
        <nav class="site-state motion-element">

          
            <div class="site-state-item site-state-posts">
              <a href="/archives">
                <span class="site-state-item-count">17</span>
                <span class="site-state-item-name">posts</span>
              </a>
            </div>
          

          
            
            
            <div class="site-state-item site-state-categories">
              
                <span class="site-state-item-count">12</span>
                <span class="site-state-item-name">categories</span>
              
            </div>
          

          
            
            
            <div class="site-state-item site-state-tags">
              
                <span class="site-state-item-count">12</span>
                <span class="site-state-item-name">tags</span>
              
            </div>
          

        </nav>

        
          <div class="feed-link motion-element">
            <a href="/atom.xml" rel="alternate">
              <i class="fa fa-rss"></i>
              RSS
            </a>
          </div>
        

        <div class="links-of-author motion-element">
          
            
              <span class="links-of-author-item">
                <a href="https://github.com/leeifme" target="_blank" title="GitHub">
                  
                    <i class="fa fa-fw fa-github"></i>
                  
                  GitHub
                </a>
              </span>
            
              <span class="links-of-author-item">
                <a href="http://weibo.com/5406937103/profile?topnav=1&wvr=6" target="_blank" title="微博">
                  
                    <i class="fa fa-fw fa-weibo"></i>
                  
                  微博
                </a>
              </span>
            
          
        </div>

        
        
          <div class="cc-license motion-element" itemprop="license">
            <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" class="cc-opacity" target="_blank">
              <img src="/images/cc-by-nc-sa.svg" alt="Creative Commons" />
            </a>
          </div>
        

        
        

        


      </section>
      
        
        <!--noindex-->
          <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
            <div class="post-toc">

              
                
              

              
                <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#前言："><span class="nav-number">1.</span> <span class="nav-text">前言：</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#首页item布局实现"><span class="nav-number">2.</span> <span class="nav-text">首页item布局实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#加载布局"><span class="nav-number">2.1.</span> <span class="nav-text">加载布局</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#根据数据来刷新界面"><span class="nav-number">2.2.</span> <span class="nav-text">根据数据来刷新界面</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#效果"><span class="nav-number">2.3.</span> <span class="nav-text">效果</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#应用页面实现"><span class="nav-number">3.</span> <span class="nav-text">应用页面实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#效果-1"><span class="nav-number">3.1.</span> <span class="nav-text">效果</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#专题页面实现"><span class="nav-number">4.</span> <span class="nav-text">专题页面实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#效果-2"><span class="nav-number">4.1.</span> <span class="nav-text">效果</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#推荐页面实现"><span class="nav-number">5.</span> <span class="nav-text">推荐页面实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#效果-3"><span class="nav-number">5.1.</span> <span class="nav-text">效果</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#排行页面实现"><span class="nav-number">6.</span> <span class="nav-text">排行页面实现</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#效果-4"><span class="nav-number">6.1.</span> <span class="nav-text">效果</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#最后"><span class="nav-number">7.</span> <span class="nav-text">最后</span></a></li></ol></div>
              

            </div>
          </section>
        <!--/noindex-->
        
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright" >
  
  &copy; 
  <span itemprop="copyrightYear">2017</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">睡沙发的沙皮狗</span>
</div>

<div class="powered-by">
  Powered by <a class="theme-link" href="http://hexo.io">Hexo</a>
</div>

<div class="theme-info">
  Theme -
  <a class="theme-link" href="https://github.com/zproo/hexo-blog">
    Next
  </a>
</div>

        

<div class="busuanzi-count">

  <script async src="https://dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>

  
    <span class="site-uv"><i class="fa fa-user"></i><span class="busuanzi-value" id="busuanzi_value_site_uv"></span></span>
  

  
    <span class="site-pv"><i class="fa fa-eye"> </i><span class="busuanzi-value" id="busuanzi_value_site_pv"></span></span>
  
  
</div>



        
      </div>
    </footer>

    <div class="back-to-top">
      <i class="fa fa-arrow-up"></i>
    </div>
  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  




  



  
  <script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script>

  
  <script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>

  
  <script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>

  
  <script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>

  
  <script type="text/javascript" src="/lib/canvas-ribbon/canvas-ribbon.js"></script>


  


  <script type="text/javascript" src="/js/src/utils.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/motion.js?v=5.0.1"></script>



  
  


  <script type="text/javascript" src="/js/src/affix.js?v=5.0.1"></script>

  <script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.0.1"></script>



  
  <script type="text/javascript" src="/js/src/scrollspy.js?v=5.0.1"></script>
<script type="text/javascript" src="/js/src/post-details.js?v=5.0.1"></script>



  


  <script type="text/javascript" src="/js/src/bootstrap.js?v=5.0.1"></script>



  



  





	

		<script type="text/javascript">
		_hcwp = window._hcwp || [];

		_hcwp.push({widget:"Bloggerstream", widget_id: 92841, selector:".hc-comment-count", label: "{\%COUNT%\}" });

		
		_hcwp.push({widget:"Stream", widget_id: 92841, xid: "coding/android/project/ApplicationMarket/应用市场(三)-页面数据填充/"});
		

		(function() {
		if("HC_LOAD_INIT" in window)return;
		HC_LOAD_INIT = true;
		var lang = (navigator.language || navigator.systemLanguage || navigator.userLanguage || "en").substr(0, 2).toLowerCase();
		var hcc = document.createElement("script"); hcc.type = "text/javascript"; hcc.async = true;
		hcc.src = ("https:" == document.location.protocol ? "https" : "http")+"://w.hypercomments.com/widget/hc/92841/"+lang+"/widget.js";
		var s = document.getElementsByTagName("script")[0];
		s.parentNode.insertBefore(hcc, s.nextSibling);
		})();
		</script>

	







  
  
  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length == 0) {
       search_path = "search.xml";
    }
    var path = "/" + search_path;
    // monitor main search box;

    function proceedsearch() {
      $("body").append('<div class="popoverlay">').css('overflow', 'hidden');
      $('.popup').fadeToggle();

    }
    // search function;
    var searchFunc = function(path, search_id, content_id) {
    'use strict';
    $.ajax({
        url: path,
        dataType: "xml",
        async: true,
        success: function( xmlResponse ) {
            // get the contents from search data
            isfetched = true;
            $('.popup').detach().appendTo('.header-inner');
            var datas = $( "entry", xmlResponse ).map(function() {
                return {
                    title: $( "title", this ).text(),
                    content: $("content",this).text(),
                    url: $( "url" , this).text()
                };
            }).get();
            var $input = document.getElementById(search_id);
            var $resultContent = document.getElementById(content_id);
            $input.addEventListener('input', function(){
                var matchcounts = 0;
                var str='<ul class=\"search-result-list\">';
                var keywords = this.value.trim().toLowerCase().split(/[\s\-]+/);
                $resultContent.innerHTML = "";
                if (this.value.trim().length > 1) {
                // perform local searching
                datas.forEach(function(data) {
                    var isMatch = true;
                    var content_index = [];
                    var data_title = data.title.trim().toLowerCase();
                    var data_content = data.content.trim().replace(/<[^>]+>/g,"").toLowerCase();
                    var data_url = data.url;
                    var index_title = -1;
                    var index_content = -1;
                    var first_occur = -1;
                    // only match artiles with not empty titles and contents
                    if(data_title != '' && data_content != '') {
                        keywords.forEach(function(keyword, i) {
                            index_title = data_title.indexOf(keyword);
                            index_content = data_content.indexOf(keyword);
                            if( index_title < 0 && index_content < 0 ){
                                isMatch = false;
                            } else {
                                if (index_content < 0) {
                                    index_content = 0;
                                }
                                if (i == 0) {
                                    first_occur = index_content;
                                }
                            }
                        });
                    }
                    // show search results
                    if (isMatch) {
                        matchcounts += 1;
                        str += "<li><a href='"+ decodeURIComponent(data_url) +"' class='search-result-title'>"+ data_title +"</a>";
                        var content = data.content.trim().replace(/<[^>]+>/g,"");
                        if (first_occur >= 0) {
                            // cut out 100 characters
                            var start = first_occur - 20;
                            var end = first_occur + 80;
                            if(start < 0){
                                start = 0;
                            }
                            if(start == 0){
                                end = 50;
                            }
                            if(end > content.length){
                                end = content.length;
                            }
                            var match_content = content.substring(start, end);
                            // highlight all keywords
                            keywords.forEach(function(keyword){
                                var regS = new RegExp(keyword, "gi");
                                match_content = match_content.replace(regS, "<b class=\"search-keyword\">"+keyword+"</b>");
                            });

                            str += "<p class=\"search-result\">" + match_content +"...</p>"
                        }
                        str += "</li>";
                    }
                })};
                str += "</ul>";
                if (matchcounts == 0) { str = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>' }
                if (keywords == "") { str = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>' }
                $resultContent.innerHTML = str;
            });
            proceedsearch();
        }
    });}

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched == false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };

    });

    $('.popup-btn-close').click(function(e){
      $('.popup').fadeOut(function() {
          $(".popoverlay").remove();
          $('body').css('overflow', '');
      });
    });
    $('.popup').click(function(e){
      e.stopPropagation();
    });
  </script>


  

  

  
  <script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.1.js"></script>
  <script>AV.initialize("6mFxqINb4RcjTGhNbtCzfWI1-gzGzoHsz", "c4qK91bIu9qFdGeimnKdriiK");</script>
  <script>
    function showTime(Counter) {
      var query = new AV.Query(Counter);
      var entries = [];
      var $visitors = $(".leancloud_visitors");

      $visitors.each(function () {
        entries.push( $(this).attr("id").trim() );
      });

      query.containedIn('url', entries);
      query.find()
        .done(function (results) {
          var COUNT_CONTAINER_REF = '.leancloud-visitors-count';

          if (results.length === 0) {
            $visitors.find(COUNT_CONTAINER_REF).text(0);
            return;
          }

          for (var i = 0; i < results.length; i++) {
            var item = results[i];
            var url = item.get('url');
            var time = item.get('time');
            var element = document.getElementById(url);

            $(element).find(COUNT_CONTAINER_REF).text(time);
          }
          for(var i = 0; i < entries.length; i++) {
            var url = entries[i];
            var element = document.getElementById(url);
            var countSpan = $(element).find(COUNT_CONTAINER_REF);
            if( countSpan.text() == '') {
              countSpan.text(0);
            }
          }
        })
        .fail(function (object, error) {
          console.log("Error: " + error.code + " " + error.message);
        });
    }

    function addCount(Counter) {
      var $visitors = $(".leancloud_visitors");
      var url = $visitors.attr('id').trim();
      var title = $visitors.attr('data-flag-title').trim();
      var query = new AV.Query(Counter);

      query.equalTo("url", url);
      query.find({
        success: function(results) {
          if (results.length > 0) {
            var counter = results[0];
            counter.fetchWhenSave(true);
            counter.increment("time");
            counter.save(null, {
              success: function(counter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(counter.get('time'));
              },
              error: function(counter, error) {
                console.log('Failed to save Visitor num, with error message: ' + error.message);
              }
            });
          } else {
            var newcounter = new Counter();
            /* Set ACL */
            var acl = new AV.ACL();
            acl.setPublicReadAccess(true);
            acl.setPublicWriteAccess(true);
            newcounter.setACL(acl);
            /* End Set ACL */
            newcounter.set("title", title);
            newcounter.set("url", url);
            newcounter.set("time", 1);
            newcounter.save(null, {
              success: function(newcounter) {
                var $element = $(document.getElementById(url));
                $element.find('.leancloud-visitors-count').text(newcounter.get('time'));
              },
              error: function(newcounter, error) {
                console.log('Failed to create');
              }
            });
          }
        },
        error: function(error) {
          console.log('Error:' + error.code + " " + error.message);
        }
      });
    }

    $(function() {
      var Counter = AV.Object.extend("Counter");
      if ($('.leancloud_visitors').length == 1) {
        addCount(Counter);
      } else if ($('.post-title-link').length > 1) {
        showTime(Counter);
      }
    });
  </script>



  
<script type="text/javascript" async src="//push.zhanzhang.baidu.com/push.js">
</script>


</body>
</html>
